package cn.tedu.carehome.foundation.controller;

import cn.tedu.carehome.foundation.pojo.dto.TellCheckInfoAddNewDto;
import cn.tedu.carehome.foundation.pojo.dto.TellCheckInfoUpdateDTO;
import cn.tedu.carehome.foundation.pojo.vo.TellCheckInfoAllOlderAddInfoVo;
import cn.tedu.carehome.foundation.pojo.vo.TellCheckInfoListItemVO;
import cn.tedu.carehome.foundation.pojo.vo.TellCheckInfoStandardVo;
import cn.tedu.carehome.foundation.service.ITellCheckInfoService;
import cn.tedu.carehome.foundation.service.ITellCheckInfoService;
import cn.tedu.carehome.foundation.unti.ExportExcel;
import cn.tedu.carehome.foundation.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;


@Slf4j
@Api(tags = "咨询登记管理")
@RequestMapping("/tellcheckInfo")
@Validated
@RestController
public class TellCheckInfoController {

    @Autowired
    ITellCheckInfoService tellcheckInfoService;

    @PostMapping("/add-new")
    public  JsonResult addNew(@RequestBody @Valid TellCheckInfoAddNewDto tellcheckInfoAddNewDto)
    {
        tellcheckInfoService.addNew(tellcheckInfoAddNewDto);
        return  JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/update")
    public  JsonResult update(@RequestBody  TellCheckInfoUpdateDTO tellcheckInfoUpdateDTO){
        System.out.println("tellcheckInfoUpdateDTO = " + tellcheckInfoUpdateDTO);
        tellcheckInfoService.update(tellcheckInfoUpdateDTO);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult deleteByid(@PathVariable("id") Long id)
    {
         tellcheckInfoService.deleteByid(id);
         return  JsonResult.ok();
    }
    @PostMapping("/delete/BatchByids")
    public JsonResult deleteBatchByids(@RequestBody Long[] ids)
    {
        tellcheckInfoService.deleteByids(ids);
        return  JsonResult.ok();
    }

    @GetMapping("/{id:[0-9]+}/selectByid")
    public TellCheckInfoStandardVo getStandarByid(@PathVariable("id") Long id)
    {
        return  tellcheckInfoService.checkByid(id);
    }

    @ApiOperation("查询数据列表分页")
    @ApiImplicitParams({@ApiImplicitParam(name="page",value = "页数",example = "1",required = true),
                       @ApiImplicitParam(name="size",value = "每页数量",example = "10",required = true),
                        @ApiImplicitParam(name="Content",value = "搜索栏内容")})
    @GetMapping("/list-limit")
    public List<TellCheckInfoListItemVO> listLimit(int page, int size, String Content)
    {
        log.debug("服务器接收到了客户端查询入住信息的请求");
        log.debug("参数为{},{},{}",page,size,Content);
        page = size*(page-1);
        return  tellcheckInfoService.listLimit(page,size,Content.trim());
    }
    @GetMapping("/list")
    public JsonResult<List<TellCheckInfoListItemVO>> list(String Content)
    {
        log.debug("服务器接收到了客户端咨询入住信息的请求");
        return JsonResult.ok(tellcheckInfoService.list(Content.trim()));
    }


    @GetMapping("/list/alloder-Info")
   public  List<TellCheckInfoAllOlderAddInfoVo> listAllolderInfo(String Content)
    {
        return tellcheckInfoService.listAllOlderInfo(Content.trim());
    }

    @GetMapping("/list/count")
     public  int count(String Content)
    {
        log.debug("开始入住登记统计数量！");
        return tellcheckInfoService.count(Content.trim());
    }

    //导出Excel
    @GetMapping("/list-excel")
    public void export(HttpServletResponse response) throws IOException {
        log.debug("进入导出excel");
        //获取需要导出的数据 注意Vo类上要加上注解
       List<TellCheckInfoListItemVO> dataList = tellcheckInfoService.list("");
        ExportExcel.exportExcel("入住登记信息","入住登记信息表",dataList,response);
        log.debug("导出excel成功");
    }
}
